package com.qiangua.lixin.qianguakeji;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageButton;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/7/30 0030.
 */
public class SecActivity extends Activity implements OnClickListener{

    private ViewPager mViewPager;
    private PagerAdapter mAdapter;
    private List<View> mViews = new ArrayList<View>();

    private ImageButton imageButton1;
    private ImageButton imageButton2;
    private ImageButton imageButton3;
    private ImageButton imageButton4;
    private ImageButton imageButton01;
    private ImageButton imageButton02;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.zhubuju);
        imageButton01 = (ImageButton) findViewById(R.id.imagebutton01);
        imageButton02 = (ImageButton) findViewById(R.id.imagebutton02);
        imageButton01.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SecActivity.this,SlidingMenu.class);
                startActivity(intent);
            }
        });
        imageButton02.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(SecActivity.this,TheActivity.class);
                startActivity(intent);
               // finish();
            }
        });

        initView();
        initEvents();
    }


    private void initEvents() {
        imageButton1.setOnClickListener(this);
        imageButton2.setOnClickListener(this);
        imageButton3.setOnClickListener(this);
        imageButton4.setOnClickListener(this);
    }

    private void initView() {
        mViewPager = (ViewPager) findViewById(R.id.viewpager);

        imageButton1 = (ImageButton) findViewById(R.id.imagebutton1);
        imageButton2 = (ImageButton) findViewById(R.id.imagebutton2);
        imageButton3 = (ImageButton) findViewById(R.id.imagebutton3);
        imageButton4 = (ImageButton) findViewById(R.id.imagebutton4);

        LayoutInflater mInflater = LayoutInflater.from(this);
        View tab01 = mInflater.inflate(R.layout.tab01, null);
        View tab02 = mInflater.inflate(R.layout.tab02,null);
        View tab03 = mInflater.inflate(R.layout.tab03,null);
        View tab04 = mInflater.inflate(R.layout.tab04,null);

        mViews.add(tab01);
        mViews.add(tab02);
        mViews.add(tab03);
        mViews.add(tab04);

        mAdapter = new PagerAdapter() {
            @Override
            public int getCount() {
                return mViews.size();
            }

            @Override
            public boolean isViewFromObject(View arg0, Object arg1) {
                return arg0 == arg1;
            }
            @Override
            public void destroyItem(ViewGroup container, int position,
                                    Object object)
            {
                container.removeView(mViews.get(position));
            }

            @Override
            public Object instantiateItem(ViewGroup container, int position)
            {
                View view = mViews.get(position);
                container.addView(view);
                return view;
            }
        };
        mViewPager.setAdapter(mAdapter);
    }

    @Override
    public void onClick(View v) {

        switch (v.getId())
        {
            case R.id.imagebutton1:
                mViewPager.setCurrentItem(0);

                break;
            case R.id.imagebutton2:
                mViewPager.setCurrentItem(1);

                break;
            case R.id.imagebutton3:
                mViewPager.setCurrentItem(2);

                break;
            case R.id.imagebutton4:
                mViewPager.setCurrentItem(3);

                break;

            default:
                break;
        }
    }



}

